#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>

int main(){
	int fds[2];
	char buf[100];
	int len;
	
	if(pipe(fds)==-1){
		perror("Failed to create pipe\n");
		exit(1);//include<stdlib.h>
	}

	while(fgets(buf,100,stdin)){//fgets(char*,int,FILE*)
		len=strlen(buf);
		if(write(fds[1],buf,len)!=len){
			perror("failed to write into pipe\n");
			break;
		}
		memset(buf,0x00,sizeof(buf));

		if((len=read(fds[0],buf,100))==-1){
			perror("failed to read from pipe\n");
			break;
		}

		if(write(1,buf,len)!=len){
			perror("failed to write to stdout\n");
			break;
		}
	}
	return 0;
}